//This script fetches img alt text and displays it as a caption

insertCaptions();
function insertCaptions(){
	//fetch all imgs
	var imgs = document.getElementById('content').getElementsByTagName("img");

	for ( var i = 0; i < imgs.length; i++){
		//get alt text
		var altName = imgs[i].getAttribute("alt");
		altName = capitaliseFirstLetter(altName);
		
		var el = document.createElement("div");
		el.className = "caption";
		
		//add img number
		el.innerHTML = "Image " + (i + 1) + ": " + altName;
		insertAfter(imgs[i], el);
	}
}
function insertAfter(referenceNode, newNode) {
    referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}

function capitaliseFirstLetter(string)
{
    return string.charAt(0).toUpperCase() + string.slice(1);
}